/**
 * 通用的两个操作数，用于数学上
 * @param {Function} operator 操作规则
 * @param {number} defaultValue 默认值
 * @returns {number} 操作的结果
 */
function createMathOperation(operator, defaultValue) {

    return (value, other) => {

        if((value === undefined || value === null) && (other !== undefined && other !== null) ) {
            return other
        }
    
        if((other === undefined || other === null) && (value !== undefined && value !== null) ) {
            return value
        }
    
        if( (value === undefined || value === null) && (other === undefined || other ===null) ){
            return defaultValue
        }

        return operator(value, other)
    }

}

export default createMathOperation